'''
Created on Oct 20, 2014

@author: azhelezny
'''
def enum(**named_values):
    return type('Enum', (), named_values)

Alleles = enum(K=1, M=2, N=3)

def getPositiveProbability(F, S):
    if(F == Alleles.K or S == Alleles.K):
        # k
        return 1.
    if(F == Alleles.M and S == Alleles.M):
        # m + m
        return 3. / 4.
    if((F == Alleles.M and S == Alleles.N) or (F == Alleles.N and S == Alleles.M)):
        # m + n
        return 1. / 2.
    return 0

k = 18
m = 23
n = 18

population = k + m + n

kProbability = k / population
mProbability = m / population
nProbability = n / population
mAfterMProbability = (m - 1) / (population - 1)
kSecondStepProbability = k / (population - 1)
mSecondStepProbability = m / (population - 1)
nSecondStepProbability = n / (population - 1)


# for each k
result = kProbability * getPositiveProbability(Alleles.K, Alleles.K)
# for m + m
result += (mProbability * mAfterMProbability * getPositiveProbability(Alleles.M, Alleles.M))
# for m + n
result += (mProbability * nSecondStepProbability * getPositiveProbability(Alleles.M, Alleles.N)) *2
# for m + k
result += (mProbability * kSecondStepProbability * getPositiveProbability(Alleles.M, Alleles.K))
# for n + k
result += (nProbability * kSecondStepProbability * getPositiveProbability(Alleles.N, Alleles.K))


print(format(result))